<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class EventosAdmin extends CI_Controller {

	function __construct(){
		parent::__construct();
		$this->load->model('eventoM');
		
	}
	
	public function index()
	{	
		$this->load->model('eventoM');
		$data2['eventos']= $this->eventoM->listarAll();
		if($this->session->userdata('logueado')){
			$data = array();
			$data['nombre'] = $this->session->userdata('nombre');
			$this->load->view('headerAdmin', $data);
		}else{
			redirect('usuarios/iniciar_sesion');
		}
		$this->load->view('eventosAdmin', $data2);
		$this->load->view('footerAdmin');

	}

	public	function agregar(){
		$this->load->library('form_validation');
		$this->load->model('eventoM');
		$evento = array(
					'nombre' => $this->input->post('nombre'),
					'fecha' => $this->input->post('fecha'),
					'hora' => $this->input->post('hora'),
					'descripcion' => $this->input->post('descripcion'),
					'cant_participantes' => $this->input->post('part'),
					
				);


		/*print_r($evento);exit();*/
		$id_generado = $this->eventoM->alta($evento);
		
		//redirect('eventosAdmin');
	}

	public function listar(){
	}

	public function modificar(){
		$id = $_GET["num"];
		$this->load->library('form_validation');
		$this->load->model('eventoM');
		$data2['evento'] = $this->eventoM->buscar($id);
		$this->load->view('detalleEvento',$data2);
	}

	public function guardarcambios(){
		$id = $this->input->post('id');
		$evento = array(
					'nombre' => $this->input->post('nombre'),
					'descripcion' => $this->input->post('descripcion'),
					'fecha' => $this->input->post('fecha'),
					'hora' => $this->input->post('hora'),
			);
		$this->load->model('eventoM');
		$ev = $this->eventoM->edit($id,$evento);
		redirect('/eventosAdmin');
        exit();

	}

	public function eliminar(){
        
		$this->load->model('eventoM');
        $id = $_GET["num"];
        $ev = $this->eventoM->baja($id);
        redirect('/eventosAdmin');
        exit();

    }

    function verDetalle(){
    	
		$id = $_GET["num"];
		// echo $id;

		$data3['evento'] = $this->eventoM->buscar($id);
		//print_r($ev);exit();
		if($this->session->userdata('logueado')){
			$data = array();
			$data['nombre'] = $this->session->userdata('nombre');
			$this->load->view('headerAdmin', $data);
		}else{
			redirect('usuarios/iniciar_sesion');
		}
		$this->load->view('detalleEvento', $data3);
		$this->load->view('footerAdmin');
		
    }
}
